package logic

import (
	"context"
	"github.com/pkg/errors"
	"mall/app/product/model"
	"mall/common/xerr"

	"mall/app/product/cmd/rpc/internal/svc"
	"mall/app/product/cmd/rpc/pb"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddAttrGroupLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAddAttrGroupLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddAttrGroupLogic {
	return &AddAttrGroupLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// AddAttrGroup 添加属性分组
func (l *AddAttrGroupLogic) AddAttrGroup(in *pb.AddAttrGroupReq) (*pb.EmptyResp, error) {
	_, err := l.svcCtx.AttrGroupModel.Insert(l.ctx, &model.PmsAttrGroup{
		AttrGroupName: in.AttrGroupName,
		Sort:          in.Sort,
		Descript:      in.Description,
		Icon:          in.Icon,
		CatelogId:     in.CategoryId,
	})
	if err != nil {
		return nil, errors.Wrapf(xerr.NewErrorWithCode(xerr.DbError), "err: %v", err)
	}
	return &pb.EmptyResp{}, nil
}
